//
//  MainTabBar.swift
//  elarc01
//
//  Created by elarc on 16/2/26.
//  Copyright © 2016年 elarc. All rights reserved.
//

import UIKit

class MainTabBar: UITabBar {

    /*
    // Only override drawRect: if you perform custom drawing.
    // An empty implementation adversely affects performance during animation.
    override func drawRect(rect: CGRect) {
        // Drawing code
    }
    */
    //按钮总数
    private let buttonCounts = 5
    
    override func layoutSubviews() {
        super.layoutSubviews()
        
        let w  = bounds.width / CGFloat(buttonCounts)
        let rect = CGRectMake(0, 0, w, bounds.height)
        
        var index = 0
        for v in subviews{
            if v is UIControl && !(v is UIButton){
                v.frame = CGRectOffset(rect, CGFloat (index) * w, 0)
                
                index += index == 1 ? 2 : 1
            }
        }
        //设置加号按钮
        compoesButton.frame = CGRectOffset(rect, 2*w, 0)
    }

    lazy var compoesButton:UIButton = {
        let btn = UIButton(type: UIButtonType.ContactAdd)
        btn.setImage(UIImage(named: "tabbar_compose_icon_add"), forState:UIControlState.Normal)
        btn.setImage(UIImage(named: "tabbar_compose_button_highlighted"), forState: UIControlState.Highlighted)
        btn.setBackgroundImage(UIImage(named: "tabbar_compose_button"), forState: UIControlState.Normal)
        self.addSubview(btn)
        return btn
    }()
}
